#!/bin/sh

# Slackware build script for Planter
# Written by klaatu at member dot fsf org

PRGNAM=planter
VERSION=${VERSION:-1.6}
BUILD=${BUILD:-1}
##% TAG=${TAG:-_SBo}  # uncomment for SBo
TAG=${TAG:-_SMi}  # strike for SBo
ARCH=noarch
DOCDIR=${DOCDIR:-/usr/doc}
MANDIR=${MANDIR:-/usr/man}
INFODIR=${INFODIR:-/usr/info}

CWD=$(pwd)
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

set -e
rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM-$VERSION
##% tar xvf $CWD/$PRGNAM-$VERSION.tar.gz  # uncomment for SBo
mkdir $PRGNAM-$VERSION  # strike for SBo
cd $PRGNAM-$VERSION
chown -Rv root:root .
find . \
 \( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) \
 -exec chmod 755 {} \; -o \
 \( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \
 -exec chmod 644 {} \;

cp -r $CWD/etc/planter $PKG/etc/
cp -r $CWD/usr/ $PKG/usr/
mkdir -p $PKG/usr/bin/ $PKG/etc || true
##% cp planter $PKG/usr/bin/  # uncomment for SBo
cp $CWD/planter $PKG/usr/bin/  # strike for SBo

# man page
mkdir -p $PKG/$INFODIR
mkdir -p $PKG/$MANDIR/man8

##% cp planter.8 $PKG/$MANDIR/man8/  # uncomment for SBo
cp $CWD/planter.8 $PKG/$MANDIR/man8/  # strike for SBo
gzip $PKG/$MANDIR/man8/sport.8

##% makeinfo sport.texinfo -o $PKG/usr/info/sport.info  # uncomment for SBo
makeinfo $CWD/sport.texinfo -o $PKG/$INFODIR/sport.info  # strike for SBo
gzip $PKG/$INFODIR/sport.info

# docs
mkdir -p $PKG/$DOCDIR/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > \
    $PKG/$DOCDIR/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

# Copy the slack-desc into ./install
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz}
